package com.kgc.sbt.util;

import com.kgc.sbt.constant.SystemConstant;

/**
 * Created on 2021/6/1.
 * <p>
 * Author: GongMingJie
 * <p>
 * Description: 封装统一返回工具类
 */
public class ResultBuildUtil {

    /**
     * Created on 2021/6/1
     * Author: GongMingJie
     * @param
     * @return
     * Description: 返回成功不带数据
     */
    public static <T> RequestResult<T> success(){
        return success(null);
    }

    /**
     * Created on 2021/6/1
     * Author: GongMingJie
     * @param
     * @return
     * Description: 返回成功带数据
     */
    public static <T> RequestResult<T> success(T t){
        RequestResult<T> requestResult = new RequestResult<>();
        requestResult.setCode(SystemConstant.SYS_RESP_SUCCESS_CODE);
        requestResult.setMsg(SystemConstant.SYS_RESP_SUCCESS_MSG);
        requestResult.setData(t);
        return requestResult;
    }

    /**
     * Created on 2021/6/1
     * Author: GongMingJie
     * @param
     * @return
     * Description: 返回失败不带数据
     */
    public static <T> RequestResult<T> fail(){
        RequestResult<T> requestResult = new RequestResult<>();
        requestResult.setCode(SystemConstant.SYS_RESP_FAIL_CODE);
        requestResult.setMsg(SystemConstant.SYS_RESP_FAIL_MSG);
        requestResult.setData(null);
        return requestResult;
    }

    /**
     * Created on 2021/6/1
     * Author: GongMingJie
     * @param
     * @return
     * Description: 返回失败不带数据，自定义状态和说明
     */
    public static <T> RequestResult<T> fail(String errCode,String errMsg){
        RequestResult<T> requestResult = new RequestResult<>();
        requestResult.setCode(errCode);
        requestResult.setMsg(errMsg);
        requestResult.setData(null);
        return requestResult;
    }
}
